package com.wl2o2o.lanqiao.xzfourteen;

import java.util.Scanner;

/** 
* @author : WLei224
* @date ：2023年2月5日 下午6:14:49 
* 
*/
public class GcdAndLcm {

	public static void main(String[] args) {
		int a = 0, b = 0;
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()) { //循环输入用于测试数据
			a = scanner.nextInt();
			b = scanner.nextInt();
			System.out.println("最大公约数：");
			System.out.println("欧几里得"+gcd(a, b));
			System.out.println("递归方法"+gcd1(a, b));
			
			System.out.println("最小公倍数：");
			System.out.println(lcm(a, b));
		}
	}
	//欧几里得方法
	public static int gcd1(int a, int b) {
		while(b>0) {
			int temp = a%b;
			a = b;
			b = temp;
		}
		return a;
	}
	//递归方法
	public static int gcd(int a, int b) {
		return b>0? gcd(b, a%b) : a;
	}
	//求最小公倍数
	public static int lcm(int a, int b) {
		return a*b/gcd(a, b);
	}
}
